package com.bitspilani.infonet.core;

import java.util.Timer;
import java.util.TimerTask;

import com.bitspilani.infonet.bo.CurrentLocation;
import com.bitspilani.infonet.bo.LastKnownLocation;
import com.bitspilani.infonet.constants.GlobalConstants;
import com.bitspilani.infonet.serviceinterface.ServiceTask;
import com.google.gson.Gson;

public class RiskSpeedListner {
	private Gson gson = new Gson();
	private static Timer riskSpeedTimer= new Timer();
	public void scheduleRiskAndSpeedListning(){
		
		TimerTask task = new TimerTask() {

			@Override  
			public void run() {
				
			try {
				CurrentLocation currentLocationDetails = new CurrentLocation();
				LastKnownLocation loc = LocationProvider.getBestKnownLocation();
				
				currentLocationDetails.setDeviceId(GlobalConstants.DEVICE_ID);
				currentLocationDetails.setVehicleTypeId(GlobalConstants.VEHICLE_TYPE_ID);
				currentLocationDetails.setCurrentLocation(loc);
				
				String currentLocationJson = gson.toJson(currentLocationDetails);
				
				 new ServiceTask().execute(GlobalConstants.GET_SPEED_LIMIT_RISK, currentLocationJson);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
				
				
			}
			
			};
			
			riskSpeedTimer.scheduleAtFixedRate(task, 0, GlobalConstants.RISK_TICK_FREQUENCY);  
	}
}
